# -*- coding: utf-8 -*-
import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel
from typing import Optional

app = FastAPI()


class City(BaseModel):
    country: str
    province: str
    is_affected: Optional[bool] = None


@app.get('/')
async def hello():
    return {'hello': 'world'}


@app.get('/city/{city}')
async def result(city: str, query_string: Optional[str] = None):
    return {'city': city, 'query_string': query_string}


@app.put('/city/{city}')
async def result(city: str, city_info: City):
    return {
        'city': city,
        'country': city_info.country,
        'is_affected': city_info.is_affected
    }


# 启动命令 uvicorn hello:app --reload
# swagger地址 http://localhost:8080/docs
# swagger地址 http://127.0.0.1:8080/redoc
if __name__ == '__main__':

    uvicorn.run(app=app, host="127.0.0.1", port=8080, debug=True)
